package com.ruoyi.web.controller.dormitory;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dormitory.domain.TbBuilding;
import com.ruoyi.dormitory.service.ITbBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 类别Controller
 *
 * @author hongyi
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/dormitory/building")
public class TbBuildingController extends BaseController
{
    @Autowired
    private ITbBuildingService tbBuildingService;

    /**
     * 查询类别列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbBuilding tbBuilding)
    {
        startPage();
        List<TbBuilding> list = tbBuildingService.selectTbBuildingList(tbBuilding);
        return getDataTable(list);
    }

    /**
     * 导出类别列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:building:export')")
    @Log(title = "类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbBuilding tbBuilding)
    {
        List<TbBuilding> list = tbBuildingService.selectTbBuildingList(tbBuilding);
        ExcelUtil<TbBuilding> util = new ExcelUtil<TbBuilding>(TbBuilding.class);
        util.exportExcel(response, list, "类别数据");
    }

    /**
     * 获取类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('dormitory:building:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbBuildingService.selectTbBuildingById(id));
    }

    /**
     * 新增类别
     */
    @PreAuthorize("@ss.hasPermi('dormitory:building:add')")
    @Log(title = "类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbBuilding tbBuilding)
    {
        return toAjax(tbBuildingService.insertTbBuilding(tbBuilding));
    }

    /**
     * 修改类别
     */
    @PreAuthorize("@ss.hasPermi('dormitory:building:edit')")
    @Log(title = "类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbBuilding tbBuilding)
    {
        return toAjax(tbBuildingService.updateTbBuilding(tbBuilding));
    }

    /**
     * 删除类别
     */
    @PreAuthorize("@ss.hasPermi('dormitory:building:remove')")
    @Log(title = "类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbBuildingService.deleteTbBuildingByIds(ids));
    }
}
